package com.xiami.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/*
创建者:虾米糖
*/
@Slf4j
@Component
@Aspect
public class TimeAspect {
    @Around("execution(* com.xiami.service.*.*(..))")//切入点表达式
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录开始时间
        long begin = System.currentTimeMillis();
        //调用原始方法
      Object proceed = joinPoint.proceed();

        //记录结束时间
        long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature()+"方法执行时间：{}ms",end-begin);

        return proceed;
    }
}
